package LiKou;

public class Test1 {
    public static void main(String[] args) {
        int[] height={0,1,0,2,1,0,1,3,2,1,2,1};
        System.out.println(MaxArea(height));
    }
    public static int MaxArea(int[] height){
        int result=0;
        int len=height.length;
        int result1=0;
        for(int i=0;i<len-1;){
            if(height[i]<height[i+1]){
                continue;
            }
            int index=i;
            while(index<len && height[index]<=height[i]){
                System.out.println(1);
                result1+=(height[i]-height[index]);
                index++;
            }
            i=index;
        }
        int result2=0;
        for(int i=len-1;i>0;){
            if(height[i]>height[i+1]){
                continue;
            }
            int index=i;
            while( index>=0 && height[index]<=height[i] ){
                result1+=(height[i]-height[index]);
                index--;
            }
            i=index;
        }
        int maxValue=0;
        for(int i=0;i<len;i++){
            if(maxValue<height[i]){
                maxValue=height[i];
            }
        }
        result=result1+result2-(maxValue*(len));
        return result;
    }
}
